<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/jquery/jquery-3.2.1.min.js"></script>
    <script src="/layui/layui.js"></script>
    <link rel="stylesheet" href="/layui/css/layui.css"/>
</head>
<body>
    <form class="layui-form">

        <div class="layui-form-item" style="margin-top: 10px">
            <label class="layui-form-label">部门名称：</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" name="name" placeholder="输入部门名称" style="width: 350px">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">创建人：</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" name="createId" disabled="disabled" style="width: 350px">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">创建时间：</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" name="createDate" disabled="disabled" style="width: 350px">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">部门描述：</label>
            <div class="layui-input-inline">
                <textarea class="layui-textarea" name="deptDescirbe" placeholder="输入部门描述" style="width: 350px"></textarea>
            </div>
        </div>

        <input type="hidden" name="updateId">
        <input type="hidden" name="updateDate">
        <input type="hidden" name="id">
        <!--确定取消-->
        <div style="float: right; margin-bottom: 10px;margin-right: 38px">
            <button type="button" lay-submit lay-filter="sub" class="layui-btn">确定</button>
            <button type="button" onclick="cancel()" class="layui-btn layui-btn-warm">取消</button>
        </div>
    </form>
</body>
<script>

    layui.use(['jquery','table','form','layer'],function () {
        var $ = layui.$,
            table = layui.table,
            form = layui.form,
            layer = layui.layer;

        //获取当前时间
        var newTime;
        getTime();
        function getTime(){
            var myDate = new Date();
            var myYear = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
            var myMonth = myDate.getMonth()+1; //获取当前月份(0-11,0代表1月)
            var myToday = myDate.getDate(); //获取当前日(1-31)
            var myDay = myDate.getDay(); //获取当前星期X(0-6,0代表星期天)
            var myHour = myDate.getHours(); //获取当前小时数(0-23)
            var myMinute = myDate.getMinutes(); //获取当前分钟数(0-59)
            var mySecond = myDate.getSeconds(); //获取当前秒数(0-59)
            newTime = myYear+'-'+myMonth+'-'+myToday+' '+myHour+':'+myMinute+':'+mySecond;
        };

        //获取当前用户信息
        var user = JSON.parse(localStorage.getItem("user"));

        //获取当前部门信息
        var id = parent.$('#id').val();
        var deptDescirbe = parent.$('#deptDescirbe').val();
        var name = parent.$('#name').val();


        $('input[name=createId]').val(user.trueName);
        $('input[name=updateId]').val(user.trueName);
        $('input[name=createDate]').val(newTime);
        $('input[name=updateDate]').val(newTime);
        $('input[name=id]').val(id);
        $('input[name=deptDescirbe]').val(deptDescirbe);
        $('input[name=name]').val(name);







        //监听提交
        form.on('submit(sub)',function(obj){

            var dept = obj.field;

            $.ajax({
                 url: '/jurisdiction/editDept'
                ,data: dept
                ,dataType: 'json'
                ,success:function(data){
                    var layer = parent.layer;
                    layer.close(layer.index);
                    layer.msg('修改成功');
                    parent.tableAjax();
                }
            })

        });

        //取消添加
        cancel = function cancel(){
            var layer = parent.layer;
            layer.close(layer.index);
        }


    });

</script>
</html>